import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:high_help_apps/common/utils/toast.dart';
import 'package:high_help_apps/common/values/colors.dart';
import 'package:high_help_apps/common/widgets/common/awesome_recommend_gallery.dart';
import 'package:high_help_apps/common/widgets/common/icon_menu/icon_menu.dart';
import 'package:high_help_apps/common/widgets/common/icon_menu/icon_menu_item.dart';
import 'package:high_help_apps/common/widgets/common/world_list_view/world_list_items.dart';

import 'community_logic.dart';
import 'community_state.dart';

class CommunityPage extends StatefulWidget {
  @override
  _CommunityPageState createState() => _CommunityPageState();
}

class _CommunityPageState extends State<CommunityPage> {
  final CommunityLogic logic = Get.put(CommunityLogic());
  final CommunityState state = Get.find<CommunityLogic>().state;

  @override
  Widget build(BuildContext context) {
    return _buildCommunityMain();
  }

  Widget _buildCommunityMain() => RefreshIndicator(
    color: AppColors.primaryElement,
    child: ListView(
      // padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
      children: [_buildIconMenu(), _buildCommunityDynamicInfoList()],
    ),
    onRefresh: () async {
      toastInfo(msg: '刷新完毕');
    },
  );

  // IconMenu
  Widget _buildIconMenu() {
    return IconMenu(
      iconList: [
        IconMenuItem(
          iconLink: 'assets/images/icons/community/community_huodong.png',
          title: '社团活动',
          onPressed: () {},
        ),
        IconMenuItem(
          iconLink: 'assets/images/icons/community/community_daka.png',
          title: '打卡监督',
          onPressed: () {},
        ),
        IconMenuItem(
          iconLink: 'assets/images/icons/community/community_laoxiang.png',
          title: '老乡交流',
          onPressed: () {},
        ),
        IconMenuItem(
          iconLink: 'assets/images/icons/community/community_school_friend.png',
          title: '校园交友',
          onPressed: () {},
        ),
        IconMenuItem(
          iconLink: 'assets/images/icons/community/community_tree.png',
          title: '吐槽树',
          onPressed: () {},
        ),
      ],
    );
  }

  Widget _buildCommunityDynamicInfoList() =>
      AwesomeRecommendGallery(
          builder: (BuildContext context, int index) {
            /// 不是真正的组件，只可以算UI的整合体，组件参数根据后端传递过来的数据格式进行改变
            return WorldListItems(
              avatar: 'https://up.enterdesk.com/edpic_360_360/96/9b/1a/969b1a5c9e32c545f5242b0e5d534e0c.jpg',
              nickname: '南宫阜阳',
              uid: 1,
              imageSrc: [
                'http://picture.ik123.com/uploads/allimg/141119/17-141119160055.jpg',
                'https://pic.netbian.com/uploads/allimg/181103/203205-1541248325fd73.jpg',
                'http://picture.ik123.com/uploads/allimg/140922/3-1409221I323.jpg'
              ],
              goods: 1500,
              time: 1627801731930,
              tags: ['动漫', '清新', '风景', '舒服', 'WDNMD', '最强大脑'],
              content: '一个人便是一座沙丘',
            );
          },
          length: 15
      );

  @override
  void dispose() {
    Get.delete<CommunityLogic>();
    super.dispose();
  }
}
